package com.ysyc.driver_ee.widget;

import android.content.Context;
import android.support.annotation.StringRes;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.ysyc.driver_ee.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SureDialog extends DialogHelp {


    @BindView(R.id.titleTv)
    TextView titleTv;
    @BindView(R.id.messageTv)
    TextView messageTv;
    private onPositiveClickListener positiveListener;

    public SureDialog(Context context) {
        super(context);
        initView();
    }

    private void initView() {
        View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_sure, null);
        ButterKnife.bind(this, dialogView);

        setContentView(dialogView);

        setCancelable(false);
        setCanceledOnTouchOutside(false);
    }

    public SureDialog setTitleText(String title) {
        titleTv.setText(title);
        return this;
    }

    public SureDialog setMessage(String message) {
        messageTv.setText(message);
        return this;
    }

    public SureDialog setTitleText(@StringRes int string) {
        titleTv.setText(getContext().getResources().getString(string));
        return this;
    }

    public SureDialog setMessage(@StringRes int string) {
        messageTv.setText(getContext().getResources().getString(string));
        return this;
    }

    public SureDialog setPositiveListener(onPositiveClickListener listener) {
        this.positiveListener = listener;
        return this;
    }

    @OnClick(R.id.sureTv)
    public void dismissClick() {
        if(positiveListener == null) {
            dismiss();
        } else {
            positiveListener.onSureClick(this);
        }
    }

    public interface onPositiveClickListener{
        void onSureClick(SureDialog dialog);
    }



}
